/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lomext.ext;

import java.util.logging.Level;
import java.util.logging.Logger;
import lomext.lom.Schema.LOM;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.filters.IsEqualFilter;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;

/**
 *
 * @author User
 */
public class Extrator {
    private Parser htmlParser;
    NodeList nodeList;

    public Extrator() {
    }

    public Extrator(String url) {
        try {
            this.htmlParser = new Parser(url); 
        } catch (ParserException ex) {
            Logger.getLogger(Extrator.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //Métodos de Extração.
    
    public NodeList extrairNodesPorTag(String tag){
        try{
            nodeList = htmlParser.parse(new TagNameFilter(tag));
            return nodeList;
        } catch (ParserException parserException){
            System.err.println(parserException.getMessage());
            return null;
        }    
    }
    
    public NodeList extrairAtributoPorTag(String tag, String atributo){
        try{
            nodeList = htmlParser.parse(new HasAttributeFilter(atributo));
            return nodeList;
        } catch (ParserException parserException){
            System.err.println(parserException.getMessage());
            return null;
        }                    
    }
}
